import axios from 'axios'

// 用户登陆
export const loginUser = (username, password) => {
  return axios.get('/v1/login', {
    params: {
      username,
      password
    }
  })
}

//  获取商品列表
export const getGoodsList = () => {
  return axios.get('/v1/goods')
}

// 获取品牌
export const getGoodsBrand = () => {
  return axios.get('/v1/shop/brand')
}
export const AddGoodsBrand = (o) => {
  return axios.post('/v1/shop/brand', o)
}

// 获取分类
export const getGoodsCat = () => {
  return axios.get('/v1/shop/cat')
}
export const AddGoodsCat = (o) => {
  return axios.post('/v1/shop/cat', o)
}

// 获取所有快递
export const getGoodsExpress = () => {
  return axios.get('/v1/shop/express')
}
export const AddGoodsExpress = (o) => {
  return axios.post('/v1/shop/express', o)
}

// 获取规格
export const getGoodsSpecWithValue = () => {
  return axios.get('/v1/shop/spec')
}

// 增加商品
export const addGoods = data => {
  return axios.post('/v1/goods', data)
}

// 获取所有文章
export const getPosts = () => {
  return axios.get('/v1/posts')
}
// 获取所有文章
export const getPostDetailById = (id) => {
  return axios.get(`/v1/post/${id}`)
}

export const addPost = (o) => {
  let user = JSON.parse(localStorage.getItem('user'))
  return axios.post('/v1/post/add?token=' + user.token, o)
}
export const delPost = (id) => {
  let user = JSON.parse(localStorage.getItem('user'))
  return axios.post(`/v1/post/del/${id}?token=` + user.token)
}
